home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 27 / CU Amiga Magazine's Super CD-ROM 27 (1998)(EMAP Images)(GB)[!][issue 1998-10].iso / CUCD / Programming / BlitzList / BlitzListFiles / c2pCACHE.ascii < prev    next >
Encoding:
Text File  |  1998-08-01  |  11.1 KB  |  515 lines

  1. WBStartup
  2. NoCli
  3.  
  4. ; Chunky-2-planar implementation by Paul West
  5. ; based on a public sourcode. MC68000 instructions only,
  6. ; but geared towards better performance on 040 and 060.
  7.  
  8. ; All following results with chunky shapes are longword aligned with no mask
  9. ; and generally multitasking is switched off
  10.  
  11. ; Please note that framerates are proportional. 37.5fps might be
  12. ; 12.5 frames slower than 50fps, but is halway between 50 and 25.
  13. ; On the other hand 75fps is 25 frames slower than 100fps but
  14. ; it still only halfway towards being twice as fast. As framerates
  15. ; double so do the number of frames accross which they span!
  16.  
  17. ; Results on 040/25Mhz CPU:
  18. ; PAL       50Hz 320x200 256-colours runs @49.7fps
  19. ; DoublePAL 48Hz 320x200 256-colours runs @47.1fps
  20. ; PAL       50Hz 320x256 256-colours runs @37.9fps
  21. ; DoublePAL 48Hz 320x256 256-colours runs @35.3fps
  22.  
  23. ; 060/50 got 59fps for 320x256
  24. ; 060/50 got 77fps for 320x200s
  25.  
  26. ; c2p and blit results on 040/25:
  27. ; 320x256x256 DoublePAL lets you blit
  28. ; - 120 32x32 256-colour shapes (140 PAL)
  29. ; - 420 16x16 256-colour shapes (500 PAL)
  30. ; while maintaining 25fps
  31.  
  32. ; c2p and blit results on 040/25:
  33. ; 320x200x256 DoublePAL lets you blit
  34. ; - 200 32x32 256-colour shapes (208 PAL)
  35. ; -~700 16x16 256-colour shapes (715 PAL)
  36. ; while maintaining 25fps
  37.  
  38. ; 256x256 on 060/50 = 76fps
  39. ; 320x256 on 060/50 = 49fps including 120 32x32 shapes
  40.  
  41. ; 320x200 on 030/50 = 23.2fps
  42. ; 320x256 on 030/50 = 13.9fps including 120 32x32 shapes
  43. ; 320x256 on 030/50 = 16.9fps
  44.  
  45.  
  46. ;Width must be multiple of 32!
  47. #scrwidth=320 ; This is the width of chunky bitmap and also of the planar bitmap
  48. #scrheight=256 ; This is the height of the chunky bitmap and also of the planar bitmap
  49.  
  50. #screensize=#scrwidth*#scrheight ; constants needed by the c2p
  51. #screensize4=#screensize/4
  52. #plane=#screensize/8
  53.  
  54. Statement c2p{A.l,B.l}
  55. c2p
  56.  
  57.   MOVE.l  d0,a0
  58.   MOVE.l  d1,a1
  59.  
  60. ;Original sourcecode text:
  61. ;
  62. ;---------------------------------------------------------------------------
  63. ;5 pass cpu only c2p for 040/060 -
  64. ;
  65. ;~13820us for 320x256 (216 rasterlines)
  66. ;with no dma activated.
  67. ;(usual copyspeed is ~13960 us)
  68. ;
  69. ;(W) Mai 1998 by Tim Bvscke aka. Azure
  70. ;azure@gmx.net
  71. ;
  72. ;This Chunky to Planar converter is converting/writing faster than
  73. ;a usual longword loop is copying from fastmem to chipmem. (Copyspeed)
  74. ;
  75. ;This is possible due to some caching-tricks.
  76. ;
  77. ;---------------------------------------------------------------------------
  78. ;IN:
  79. ; a0   =source
  80. ; a1   =target
  81. ;----------------------------------------------------------------------------
  82.  
  83.  
  84.  
  85. ;MERGE    d1,d2,tmp,mask,shift
  86. Macro MERGE
  87.   MOVE.l   `2,`3
  88.   LSR.l   #`5,`3
  89.     EOR.l    `1,`3
  90.     AND.l    `4,`3
  91.     EOR.l    `3,`1
  92.     LSL.l   #`5,`3
  93.     EOR.l    `3,`2
  94. End Macro
  95.  
  96. Macro MERGE1
  97.   MOVE.l   `2,`3
  98.   LSR.l    #1,`3
  99.     EOR.l    `1,`3
  100.     AND.l    `4,`3
  101.     EOR.l    `3,`1
  102.     ADD.l    `3,`3
  103.     EOR.l    `3,`2
  104. End Macro
  105.  
  106. Macro MERGEw
  107.     SWAP  `2
  108.     EOR.w `1,`2
  109.     EOR.w `2,`1
  110.     EOR.w `1,`2
  111.     SWAP  `2
  112. End Macro
  113.  
  114. _chunky2planar
  115.  
  116.     MOVEM.l d0-a6,-(a7)
  117.     MOVE.l  #screensize,d0
  118.  
  119.     LEA 0(a0,d0.l),a2
  120.     MOVE.l  a2,smc+2
  121.  
  122.     MOVEM.l a0/a1/a6,-(a7)
  123.     MOVE.l  $4,a6
  124.     JSR -636(a6)  ;flush caches
  125.     MOVEM.l (a7)+,a0/a1/a6
  126.  
  127.     MOVE.l  (a0),d0
  128.     MOVE.l  2*4+0(a0),d2
  129.     MOVE.l  4*4+0(a0),d4
  130.     MOVE.l  6*4+0(a0),d6
  131.  
  132.     !MERGEw{d0,d4}
  133.     !MERGEw{d2,d6}
  134.  
  135.     !MERGE{d0,d2,d3,#$00FF00FF,8}
  136.     !MERGE{d4,d6,d3,#$00FF00FF,8}
  137.  
  138.     MOVE.l  1*4(a0),d1
  139.     MOVE.l  3*4(a0),d3
  140.     MOVE.l  5*4(a0),d5
  141.     MOVE.l  7*4(a0),d7
  142.  
  143.     ADDA.w  #32,a0
  144.     MOVE.l  d4,a6   ;  d3->a6
  145.  
  146.     !MERGEw{d1,d5}
  147.     ADD.l #screensize4*1,a1
  148.     !MERGEw{d3,d7}
  149.     !MERGE{d5,d7,d4,#$00FF00FF,8}
  150.     !MERGE{d1,d3,d4,#$00FF00FF,8}
  151.     !MERGE{d0,d1,d4,#$0F0F0F0F,4}
  152.     !MERGE{d2,d3,d4,#$0F0F0F0F,4}
  153.     !MERGE{d6,d7,d4,#$0F0F0F0F,4}
  154.     EXG.l d1,a6   ;d4-> a6
  155.     !MERGE{d1,d5,d4,#$0F0F0F0F,4}
  156.     ADD.l #screensize4*1,a1
  157.     !MERGE{d0,d1,d4,#$33333333,2}
  158.     !MERGE{d2,d6,d4,#$33333333,2}
  159.     ADD.l #screensize4*1+4,a1
  160.     !MERGE{d3,d7,d4,#$33333333,2}
  161.     EXG.l d1,a6   ;d4=a6
  162.     !MERGE1{d0,d2,d4,#$55555555}
  163.     MOVE.l  d0,plane(a1) ;->Plane 7
  164.     EXG.l d0,a6
  165.     !MERGE{d1,d5,d4,#$33333333,2}
  166.     !MERGE1{d0,d6,d4,#$55555555}
  167.     MOVE.l  d0,a5
  168.     !MERGE1{d1,d3,d4,#$55555555}
  169.     MOVE.l  d2,(a1)
  170.     MOVE.l  d6,a4
  171.     MOVE.l  d1,a3
  172.     SUB.l #screensize4*3,a1
  173.     !MERGE1{d5,d7,d4,#$55555555}
  174.     MOVE.l  d7,a6
  175.     MOVE.l  d3,a2
  176. loop
  177.     TST.w 0*16+6(a0)
  178.     TST.w 1*16+6(a0)
  179.     TST.w 2*16+6(a0)
  180.     TST.w 3*16+6(a0)
  181.  
  182.     TST.w 4*16+6(a0)
  183.     TST.w 5*16+6(a0)
  184.     TST.w 6*16+6(a0)
  185.     TST.w 7*16+6(a0)  ;this is the tricky part
  186.  
  187.     MOVE.l  (a0),d0
  188.     MOVE.l  2*4+0(a0),d2
  189.     MOVE.l  4*4+0(a0),d4
  190.     MOVE.l  6*4+0(a0),d6
  191.  
  192.     MOVE.l  d5,plane(a1) ;  Plane 1
  193.  
  194.     !MERGEw{d0,d4}
  195.     !MERGEw{d2,d6}
  196.  
  197.     !MERGE{d0,d2,d3,#$00FF00FF,8}
  198.     !MERGE{d4,d6,d3,#$00FF00FF,8}
  199.  
  200.     MOVE.l  1*4(a0),d1
  201.     MOVE.l  3*4(a0),d3
  202.     MOVE.l  5*4(a0),d5
  203.     MOVE.l  7*4(a0),d7
  204.  
  205.     ADDA.l  #32,a0
  206.     MOVE.l  a6,(a1)   ;  Plane 0
  207.     MOVE.l  d4,a6   ;  d3->a6
  208.  
  209.     !MERGEw{d1,d5}
  210.     ADD.l #screensize4*1,a1
  211.     !MERGEw{d3,d7}
  212.  
  213.     MOVE.l  a3,plane(a1) ; 3
  214.  
  215.     !MERGE{d5,d7,d4,#$00FF00FF,8}
  216.     !MERGE{d1,d3,d4,#$00FF00FF,8}
  217.     !MERGE{d0,d1,d4,#$0F0F0F0F,4}
  218.     !MERGE{d2,d3,d4,#$0F0F0F0F,4}
  219.     MOVE.l  a2,(a1)   ; 2
  220.     !MERGE{d6,d7,d4,#$0F0F0F0F,4}
  221.     EXG.l d1,a6   ;d4-> a6
  222.     !MERGE{d1,d5,d4,#$0F0F0F0F,4}
  223.     ADD.l #screensize4*1,a1
  224.     MOVE.l  a5,plane(a1) ; 5
  225.  
  226.     !MERGE{d0,d1,d4,#$33333333,2}
  227.     !MERGE{d2,d6,d4,#$33333333,2}
  228.     MOVE.l  a4,(a1)   ; 4
  229.     ADD.l #screensize4*1+4,a1
  230.     !MERGE{d3,d7,d4,#$33333333,2}
  231.     EXG.l d1,a6   ;d4=a6
  232.  
  233.     !MERGE1{d0,d2,d4,#$55555555}
  234.  
  235.     MOVE.l  d0,plane(a1) ;->Plane 7
  236.  
  237.     EXG.l d0,a6
  238.  
  239.     !MERGE{d1,d5,d4,#$33333333,2}
  240.     !MERGE1{d0,d6,d4,#$55555555}
  241.     MOVE.l  d0,a5
  242.     !MERGE1{d1,d3,d4,#$55555555}
  243.     MOVE.l  d2,(a1)
  244.     MOVE.l  d6,a4
  245.     MOVE.l  d1,a3
  246.     SUB.l #screensize4*3,a1
  247.     !MERGE1{d5,d7,d4,#$55555555}
  248.     MOVE.l  d7,a6
  249.     MOVE.l  d3,a2
  250.  
  251.  
  252.     MOVE.l  (a0),d0
  253.     MOVE.l  2*4+0(a0),d2
  254.     MOVE.l  4*4+0(a0),d4
  255.     MOVE.l  6*4+0(a0),d6
  256.  
  257.     MOVE.l  d5,plane(a1) ;  Plane 1
  258.  
  259.     !MERGEw{d0,d4}
  260.     !MERGEw{d2,d6}
  261.  
  262.     !MERGE{d0,d2,d3,#$00FF00FF,8}
  263.     !MERGE{d4,d6,d3,#$00FF00FF,8}
  264.  
  265.     MOVE.l  1*4(a0),d1
  266.     MOVE.l  3*4(a0),d3
  267.     MOVE.l  5*4(a0),d5
  268.     MOVE.l  7*4(a0),d7
  269.  
  270.     ADDA.l  #32,a0
  271.     MOVE.l  a6,(a1)   ;  Plane 0
  272.     MOVE.l  d4,a6   ;  d3->a6
  273.  
  274.     !MERGEw{d1,d5}
  275.     ADD.l #screensize4*1,a1
  276.     !MERGEw{d3,d7}
  277.  
  278.     MOVE.l  a3,plane(a1) ; 3
  279.  
  280.     !MERGE{d5,d7,d4,#$00FF00FF,8}
  281.     !MERGE{d1,d3,d4,#$00FF00FF,8}
  282.     !MERGE{d0,d1,d4,#$0F0F0F0F,4}
  283.     !MERGE{d2,d3,d4,#$0F0F0F0F,4}
  284.     MOVE.l  a2,(a1)   ; 2
  285.     !MERGE{d6,d7,d4,#$0F0F0F0F,4}
  286.     EXG.l d1,a6   ;d4-> a6
  287.     !MERGE{d1,d5,d4,#$0F0F0F0F,4}
  288.     ADD.l #screensize4*1,a1
  289.     MOVE.l  a5,plane(a1) ; 5
  290.  
  291.     !MERGE{d0,d1,d4,#$33333333,2}
  292.     !MERGE{d2,d6,d4,#$33333333,2}
  293.     MOVE.l  a4,(a1)   ; 4
  294.     ADD.l #screensize4*1+4,a1
  295.     !MERGE{d3,d7,d4,#$33333333,2}
  296.     EXG.l d1,a6   ;d4=a6
  297.  
  298.     !MERGE1{d0,d2,d4,#$55555555}
  299.  
  300.     MOVE.l  d0,plane(a1) ;->Plane 7
  301.  
  302.     EXG.l d0,a6
  303.  
  304.     !MERGE{d1,d5,d4,#$33333333,2}
  305.     !MERGE1{d0,d6,d4,#$55555555}
  306.     MOVE.l  d0,a5
  307.     !MERGE1{d1,d3,d4,#$55555555}
  308.     MOVE.l  d2,(a1)
  309.     MOVE.l  d6,a4
  310.     MOVE.l  d1,a3
  311.     SUB.l #screensize4*3,a1
  312.     !MERGE1{d5,d7,d4,#$55555555}
  313.     MOVE.l  d7,a6
  314.     MOVE.l  d3,a2
  315.  
  316.  
  317.     MOVE.l  (a0),d0
  318.     MOVE.l  2*4+0(a0),d2
  319.     MOVE.l  4*4+0(a0),d4
  320.     MOVE.l  6*4+0(a0),d6
  321.  
  322.     MOVE.l  d5,plane(a1) ;  Plane 1
  323.  
  324.     !MERGEw{d0,d4}
  325.     !MERGEw{d2,d6}
  326.  
  327.     !MERGE{d0,d2,d3,#$00FF00FF,8}
  328.     !MERGE{d4,d6,d3,#$00FF00FF,8}
  329.  
  330.     MOVE.l  1*4(a0),d1
  331.     MOVE.l  3*4(a0),d3
  332.     MOVE.l  5*4(a0),d5
  333.     MOVE.l  7*4(a0),d7
  334.  
  335.     ADDA.l  #32,a0
  336.     MOVE.l  a6,(a1)   ;  Plane 0
  337.     MOVE.l  d4,a6   ;  d3->a6
  338.  
  339.     !MERGEw{d1,d5}
  340.     ADD.l #screensize4*1,a1
  341.     !MERGEw{d3,d7}
  342.  
  343.     MOVE.l  a3,plane(a1) ; 3
  344.  
  345.     !MERGE{d5,d7,d4,#$00FF00FF,8}
  346.     !MERGE{d1,d3,d4,#$00FF00FF,8}
  347.     !MERGE{d0,d1,d4,#$0F0F0F0F,4}
  348.     !MERGE{d2,d3,d4,#$0F0F0F0F,4}
  349.     MOVE.l  a2,(a1)   ; 2
  350.     !MERGE{d6,d7,d4,#$0F0F0F0F,4}
  351.     EXG.l d1,a6   ;d4-> a6
  352.     !MERGE{d1,d5,d4,#$0F0F0F0F,4}
  353.     ADD.l #screensize4*1,a1
  354.     MOVE.l  a5,plane(a1) ; 5
  355.  
  356.     !MERGE{d0,d1,d4,#$33333333,2}
  357.     !MERGE{d2,d6,d4,#$33333333,2}
  358.     MOVE.l  a4,(a1)   ; 4
  359.     ADD.l #screensize4*1+4,a1
  360.     !MERGE{d3,d7,d4,#$33333333,2}
  361.     EXG.l d1,a6   ;d4=a6
  362.  
  363.     !MERGE1{d0,d2,d4,#$55555555}
  364.  
  365.     MOVE.l  d0,plane(a1) ;->Plane 7
  366.  
  367.     EXG.l d0,a6
  368.  
  369.     !MERGE{d1,d5,d4,#$33333333,2}
  370.     !MERGE1{d0,d6,d4,#$55555555}
  371.     MOVE.l  d0,a5
  372.     !MERGE1{d1,d3,d4,#$55555555}
  373.     MOVE.l  d2,(a1)
  374.     MOVE.l  d6,a4
  375.     MOVE.l  d1,a3
  376.     SUB.l #screensize4*3,a1
  377.     !MERGE1{d5,d7,d4,#$55555555}
  378.     MOVE.l  d7,a6
  379.     MOVE.l  d3,a2
  380.  
  381. smc
  382.     CMP.l #$0BADC0DE,a0
  383.     BGE   quit
  384.  
  385.     MOVE.l  (a0),d0
  386.     MOVE.l  2*4+0(a0),d2
  387.     MOVE.l  4*4+0(a0),d4
  388.     MOVE.l  6*4+0(a0),d6
  389.  
  390.     MOVE.l  d5,plane(a1) ;  Plane 1
  391.  
  392.     !MERGEw{d0,d4}
  393.     !MERGEw{d2,d6}
  394.  
  395.     !MERGE{d0,d2,d3,#$00FF00FF,8}
  396.     !MERGE{d4,d6,d3,#$00FF00FF,8}
  397.  
  398.     MOVE.l  1*4(a0),d1
  399.     MOVE.l  3*4(a0),d3
  400.     MOVE.l  5*4(a0),d5
  401.     MOVE.l  7*4(a0),d7
  402.  
  403.     ADDA.w  #32,a0
  404.     MOVE.l  a6,(a1)   ;  Plane 0
  405.     MOVE.l  d4,a6   ;  d3->a6
  406.  
  407.     !MERGEw{d1,d5}
  408.     ADD.l #screensize4*1,a1
  409.  
  410.     !MERGEw{d3,d7}
  411.  
  412.     MOVE.l  a3,plane(a1) ; 3
  413.     !MERGE{d5,d7,d4,#$00FF00FF,8}
  414.     !MERGE{d1,d3,d4,#$00FF00FF,8}
  415.     !MERGE{d0,d1,d4,#$0F0F0F0F,4}
  416.     MOVE.l  a2,(a1)   ; 2
  417.     !MERGE{d2,d3,d4,#$0F0F0F0F,4}
  418.     !MERGE{d6,d7,d4,#$0F0F0F0F,4}
  419.     EXG.l d1,a6   ;d4-> a6
  420.     !MERGE{d1,d5,d4,#$0F0F0F0F,4}
  421.     ADD.l #screensize4*1,a1
  422.  
  423.     MOVE.l  a5,plane(a1) ; 5
  424.  
  425.     !MERGE{d0,d1,d4,#$33333333,2}
  426.     !MERGE{d2,d6,d4,#$33333333,2}
  427.     MOVE.l  a4,(a1)   ; 4
  428.     ADD.l #screensize4*1+4,a1
  429.     !MERGE{d3,d7,d4,#$33333333,2}
  430.     EXG.l d1,a6   ;d4=a6
  431.     !MERGE1{d0,d2,d4,#$55555555}
  432.  
  433.     MOVE.l  d0,plane(a1) ;->Plane 7
  434.  
  435.     EXG.l d0,a6
  436.     !MERGE{d1,d5,d4,#$33333333,2}
  437.     !MERGE1{d0,d6,d4,#$55555555}
  438.     MOVE.l  d0,a5
  439.     !MERGE1{d1,d3,d4,#$55555555}
  440.     MOVE.l  d2,(a1)
  441.     MOVE.l  d6,a4
  442.     MOVE.l  d1,a3
  443.     SUB.l #screensize4*3,a1
  444.     !MERGE1{d5,d7,d4,#$55555555}
  445.     MOVE.l  d7,a6
  446.     MOVE.l  d3,a2
  447.  
  448.     JMP loop
  449. quit
  450.     MOVE.l  d5,plane(a1)
  451.     MOVE.l  a6,(a1)
  452.     ADD.l #screensize4*1,a1
  453.     MOVE.l  a3,plane(a1)
  454.     MOVE.l  a2,(a1)
  455.     ADD.l #screensize4*1,a1
  456.     MOVE.l  a5,plane(a1)
  457.     MOVE.l  a4,(a1)
  458.  
  459.     MOVEM.l (a7)+,d0-a6
  460.  
  461.   AsmExit
  462. End Statement
  463.  
  464.  
  465.  
  466. blitzprogram
  467. ; Setup
  468. InitBank 0,(#scrwidth*#scrheight)+1000,2|65536 ; Chipram planar buffer
  469. CludgeBitMap 0,#scrwidth,#scrheight,8,Bank(0)+8
  470. InitPalette 0,256
  471. For c=0 To 255
  472.   AGAPalRGB 0,c,Rnd(c),Rnd(c),Rnd(c)
  473. Next c
  474. AGAPalRGB 0,0,0,0,0
  475. Screen 0,0,0,#scrwidth,#scrheight,8,0,"c2p test",0,0,0
  476. Use Palette 0
  477. VWait 50
  478. baseaddress1.l=AllocMem(#scrwidth*#scrheight,$10000) ; Fastram chunky buffer
  479.  
  480. ; Put something into the chunky buffer so we can see it working
  481. GetReg a0,baseaddress1
  482. MOVE.l  #0,d0
  483. MOVE.l  #screensize-1,d1
  484. cloop
  485.   MOVE.b  d0,(a0)+
  486.   ADDQ.l  #1,d0
  487.   SUBQ.l  #1,d1
  488.   TST.l   d1
  489.   BLT     done
  490.   BRA     cloop
  491. done
  492.  
  493. ; Do the c2p test
  494. VWait 20
  495. Forbid_
  496. VWait
  497. ResetTimer
  498. For time=1 To 500
  499.   c2p{baseaddress1,Bank(0)+4} ; Convert chunky to planar
  500. Next time
  501. t=Ticks
  502. VWait 2 : Permit_
  503. VWait 20
  504. FindScreen 0
  505. Window 0,0,11,640,100,0,"Test results for c2p",0,0
  506. WindowOutput 0
  507. NPrint "Routine performed @ ",50/(t/500),"fps - ",t," ticks"
  508. NPrint " "
  509. NPrint "Press mousebutton..."
  510. Free Screen 0
  511. MouseWait
  512. Free Window 0
  513. End
  514.  
  515.